<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增日报')" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include ="include :: select2-css"/> 
	<!-- 	<th:block th:include="include :: bootstrap-select-css" /> -->
    
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-hxDayReport-add">
			<input type="text" hidden="true" id="projectId" name="projectId" required>
			<input type="text" hidden="true" id="projectType" name="projectType" required>
			<input type="text" hidden="true" id="proname" name="proname" required>
 			<input type="text" hidden="true" id="workDate" name="workDate" th:value="${dateStr}" required>		
 			
 			<div class="form-group">
				<label class="col-xs-2 control-label">工作类型：</label>
				<!-- <div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('work_type')}" >
						<input type="radio" th:id="${dict.dictCode}" name="workType" th:value="${dict.dictValue}" th:checked="${dict.default}" onclick="worktype(1)">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}" ></label>
					</div>
				</div> -->
				&nbsp;&nbsp;<input type="radio" name="workType" value="1" onclick="worktype(1)" width="30px;" checked="checked">项目内工作
				&nbsp;&nbsp;&nbsp;<input type="radio" name="workType" value="2" onclick="worktype(2)" width="30px;">项目外工作
			</div>
			
			<div class="form-group" style="display: none" id="xmwDiv">
				<label class="col-xs-2 control-label">项目外类型：</label>
				<div class="col-sm-10">
					<div  th:each="dict : ${@dict.getType('except_project_in_type')}">
						<input type="radio" th:id="${dict.dictCode}" name="exceptProjectType" th:dictLable="${dict.dictLabel}" th:value="${dict.dictValue}"  >
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
		  
		  <div class="form-group"  id="xmnDiv">	
				<label class="col-xs-2 control-label">所属项目：</label>
                        <div class="col-sm-8">
                            <select id="projectSelect" class="form-control select2-multiple"   required>
								<option>请选择项目</option>
								<option th:each="project:${projects}" th:value="${project.id}" th:attr="projecttype=${project.type}"  th:text="${project.proname}"></option>
							</select>
                        </div>
			</div>
	  		<div class="form-group">	
				<label class="col-xs-2 control-label">工作时长/小时：</label>
				<div class="col-sm-8">
					<input id="workTime" name="workTime" class="form-control zhsCount" type="text"  required ><font color="red">[工时统计最小单位0.5小时]</font>
				</div>
			</div>
					
			<div class="form-group">	
				<label class="col-xs-2 control-label">工作内容：</label>
				<div class="col-sm-8">
					<textarea  class="form-control" rows="10" cols="" id="workDesc" name="workDesc" required  ></textarea>
				</div>
			</div>
			<div class="form-group" hidden="true">	
				<label class="col-sm-3 control-label">日报所属用户ID：</label>
				<div class="col-sm-8">
					<input id="userId" name="userId" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
       <th:block th:include="include :: datetimepicker-js" />
       <th:block th:include ="include :: select2-js"/>
        <!-- <th:block th:include="include :: bootstrap-select-js" /> -->
    <script type="text/javascript">
	
    $(function(){
    	
    	
	    $("#workDate").datetimepicker({
	    		minView: "month", //选择日期后，不会再跳转去选择时分秒    
	    		format: "yyyy-mm-dd",
			    startView: 2,
			    todayBtn:  1,
		        todayHighlight: 1,
			    autoclose: true
			    
			});
	    
	    $("input[name=exceptProjectType]").click(function(e){
	    	  
	    	   var proname = $(this).attr("dictLable");
	    	   $("#proname").val(proname);
	   });
	    
	    $('#projectSelect').select2({
            placeholder:"请选择项目",
            allowClear: true
        });
	    
	    $('#projectSelect').on('select2:select', function (e) {
	    	  $("#proname").val("");
	    	  var projectId = e.params.data.id;
	    	  var proname = e.params.data.text;
	    	  $("#proname").val(proname);
	    	  
	    	  var projectType = $("#projectSelect").find("option:selected").attr("projecttype"); //获取自定义属性 项目类型projecttype
	    	  $('#projectId').val(projectId);
	    	  $('#projectType').val(projectType);
	    });
    });	
    var prefix = ctx + "system/hxDayReport"
		$("#form-hxDayReport-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
    
    function worktype(workType){
    	if(workType == 1){ 
    		 window.location.reload();  // 切换工作类型时 -  清空不了下拉值 只能刷新了
    	}
    	
    	if(workType == 1){ //项目内工作
    		$("#xmnDiv").show();
    		$("#xmwDiv").hide();
    	}
    	if(workType == 2){ //项目外工作
    		$("#xmwDiv").show();
    		$("#xmnDiv").hide();
    	}
    	
    }
		function submitHandler() {
			  var projectId = $('#projectId').val();
			  var proname = $("#proname").val();
			  var workType = $('input[name="workType"]:checked').val(); 
			  if(workType ==1 && projectId =='' || projectId ==null){
				  $.modal.alertWarning("请选择项目!");
				  return;
				 // $('#workDesc').val('');
			  }
			  
			  if(proname == '' || proname == null){
				  $.modal.alertWarning("请选择项目!");
				  return;
				  //$('#workDesc').val('');
			  }
		   if(!$.validate.form()){
	        	return;
	        } 
			  
			var formattDesc = '';
			var workDesc = $('#workDesc').val();
		    var workDescArr = workDesc.split('\n');
		    for(var i=0;i<workDescArr.length;i++){
		    	if(workDescArr[i] !='' && workDescArr[i] != null){
		    		formattDesc += workDescArr[i]+'@@';
			    }
		    }
		    $('#workDesc').val(formattDesc); //工作描述追加 @@ 字符，方便日历格子中分条显示
		    

		    if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-hxDayReport-add').serialize());
	        }
	    }
/* 		function selectProject(){
			$.modal.open("选择项目", ctx + "system/hxProject/chooseProject");
		} */
	</script>
</body>
</html>
